<template>
	<view>
		<view v-for="(item, index) in questData.content">
			<quest-section v-model="questData.content[index]"></quest-section>
		</view>
		<button @click="handleSubmit">提交</button>
		{{questData.content}}
	</view>
</template>

<script setup>
	import {
		onMounted
	} from 'vue';
	const Data = reactive({
		questData: {
			content:[]
		},
	})
	const {
		questData
	} = toRefs(Data)
	onLoad((options) => {
		http.request({
			url: '/mall4cloud_feedback/quest/ua/searchQuestById?questId=' + options.questId,
			method: 'GET'
		}).then((res) => {
			res.content = JSON.parse(res.content)
			Data.questData = res
		})
	})
	onMounted(() => {

	})

	function handleSubmit() {
		let completed = true
		Data.questData.content.forEach(quest=>{
			if(!quest.answer){
				completed=false
			}
		})
		if(!completed){
			uni.showToast({
				title: '您还未完成所有问题',
				icon: 'none',
				duration: 500
			})
			return
		}
		http.request({
			url: '/mall4cloud_feedback/commit/addCommit',
			method: 'POST',
			data: {
				questId: Data.questData.questId,
				content: JSON.stringify(Data.questData.content)
			}
		}).then((res) => {
			uni.showToast({
				title: '提交问卷成功',
				icon: 'none',
				duration: 500
			})
		})
	}
</script>

<style lang="scss" scoped>
	@use "quest";
</style>